package com.century.sjt.adapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.StringRequest;
import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.activity.Topic.ClickLikeListActivity;
import com.century.sjt.activity.Topic.HomepageActivity;
import com.century.sjt.activity.Topic.MyTopicDetail;
import com.century.sjt.activity.Topic.ZonePictureActivity;
import com.century.sjt.entity.ItemBean;
import com.century.sjt.entity.Praise;
import com.century.sjt.entity.SjtUser;
import com.century.sjt.fragment.SocialTabSquareFragment;
import com.century.sjt.util.Constant;
import com.century.sjt.util.TipUtil;
import com.century.sjt.widget.picture.IBaseConstant;
import com.makeramen.roundedimageview.RoundedImageView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;


public class MyTopicListAdapter extends BaseAdapter {

    private LayoutInflater mLayoutInflater;
    // 映射数据
    private List<ItemBean> mDataList;
    private long mSumTime;
    private RequestQueue mQueue;
    private Context context;
    private ViewHolder holder;
    private Handler mHandler;

    private List<ImageView> LisetImageView=new ArrayList<>();
    private List<Praise> mPraiseList = new ArrayList<>();
    public MyTopicListAdapter(Context context, List<ItemBean> list, RequestQueue mQueue, Handler mHandler) {
        mLayoutInflater = LayoutInflater.from(context);
        this.mDataList = list;
        this.mQueue = mQueue;
        this.context = context;
        this.mHandler = mHandler;
    }

    // 获取数据量
    @Override
    public int getCount() {
        return mDataList.size();
    }

    // 获取对应ID项对应的Item
    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    // 获取对应项ID
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        // 文艺式 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        //获取纳秒时间 更加精确
//        long start = System.nanoTime();
//        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            //由于我们只需要将XML转化为View，并不涉及到具体的布局，所以第二个参数通常设置为null
            convertView = mLayoutInflater.inflate(R.layout.my_social_zone_lv_item, null);
//            holder.img = (NetworkImageView) convertView.findViewById(R.id.niv_social_zone_image);
            holder.img = (RoundedImageView) convertView.findViewById(R.id.niv_social_zone_image);
            holder.title = (TextView) convertView.findViewById(R.id.niv_social_zone_title);
            holder.time = (TextView) convertView.findViewById(R.id.niv_social_zone_time);
            holder.content = (TextView) convertView.findViewById(R.id.niv_social_zone_content);
            holder.img1 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image1);
            holder.img2 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image2);
            holder.img3 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image3);
            holder.img4 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image4);
            holder.img5 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image5);
            holder.img6 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image6);
            holder.img7 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image7);
            holder.img8 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image8);
            holder.img9 = (ImageView) convertView.findViewById(R.id.niv_social_zone_image9);
            holder.llrow1 = (LinearLayout) convertView.findViewById(R.id.ll_social_zone_row1);
            holder.llrow2 = (LinearLayout) convertView.findViewById(R.id.ll_social_zone_row2);
            holder.llrow3 = (LinearLayout) convertView.findViewById(R.id.ll_social_zone_row3);
            holder.praiseNum = (TextView) convertView.findViewById(R.id.tv_my_social_zone_praiseNum);
            holder.commentNum = (TextView) convertView.findViewById(R.id.tv_my_social_zone_commentNum);
            holder.llpraiseNum = (LinearLayout) convertView.findViewById(R.id.ll_my_social_zone_praiseNum);
            holder.llcommentNum = (LinearLayout) convertView.findViewById(R.id.ll_my_social_zone_commentNum);
            holder.llshare = (LinearLayout) convertView.findViewById(R.id.ll_my_social_zone_share);
            holder.lldelete = (LinearLayout) convertView.findViewById(R.id.ll_delete);
//            holder.llGood = (LinearLayout) convertView.findViewById(R.id.ll_isgood);
            holder.ll_isgood = (LinearLayout) convertView.findViewById(R.id.ll_isgood);

            holder.tvIsGood = (TextView) convertView.findViewById(R.id.tv_isgood);
            holder.icon_linear_like = (TextView) convertView.findViewById(R.id.icon_linear_like);
            holder.icon_information = (TextView) convertView.findViewById(R.id.icon_information);
            holder.icon_trash = (TextView) convertView.findViewById(R.id.icon_trash);
            holder.icon_share = (TextView) convertView.findViewById(R.id.icon_share);
            holder.icon_jump = (TextView) convertView.findViewById(R.id.icon_jump);
            holder.llcomment = (LinearLayout) convertView.findViewById(R.id.ll_comment);
            holder.llcomment1 = (LinearLayout) convertView.findViewById(R.id.ll_comment1);
            holder.llcomment2 = (LinearLayout) convertView.findViewById(R.id.ll_comment2);
            holder.llcomment3 = (LinearLayout) convertView.findViewById(R.id.ll_comment3);
            holder.tvCommentName1 = (TextView) convertView.findViewById(R.id.tv_commentname1);
            holder.tvCommentName2 = (TextView) convertView.findViewById(R.id.tv_commentname2);
            holder.tvCommentName3 = (TextView) convertView.findViewById(R.id.tv_commentname3);
            holder.tvComment1 = (TextView) convertView.findViewById(R.id.tv_comment1);
            holder.tvComment2 = (TextView) convertView.findViewById(R.id.tv_comment2);
            holder.tvComment3 = (TextView) convertView.findViewById(R.id.tv_comment3);
            holder.ll_look_all_comment = (LinearLayout) convertView.findViewById(R.id.ll_look_all_comment);
            holder.tv_isgood = (TextView) convertView.findViewById(R.id.tv_isgood);
            Typeface iconfont = Typeface.createFromAsset(context.getAssets(), "iconfont.ttf");
            holder.icon_linear_like.setTypeface(iconfont);
            holder.icon_information.setTypeface(iconfont);
            holder.icon_trash.setTypeface(iconfont);
            holder.icon_share.setTypeface(iconfont);
            holder.icon_jump.setTypeface(iconfont);
            convertView.setTag(holder);

            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //取出bean对象
        final ItemBean bean = mDataList.get(position);
        //设置控件的数据

//        删除话题
        holder.lldelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle(context.getResources().getString(R.string.text_prompt));
                builder.setMessage(context.getString(R.string.error_is_delete));
                builder.setPositiveButton(context.getResources().getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        deleteTopic(bean.topicId, position);
                    }
                });
                builder.setNegativeButton(context.getResources().getString(R.string.btn_no), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.setCancelable(false);
                builder.create().show();
            }
        });


//        holder.img.setDefaultImageResId(R.mipmap.head_image_defualt);
//        holder.img.setErrorImageResId(R.mipmap.head_image_defualt);
        SjtUser user = bean.user;
        String imgUrl = Constant.ImageHost_Small + user.getImage();
        Glide.with(context).load(imgUrl).into(holder.img);
        //我的话题头像点击
        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, HomepageActivity.class).putExtra("userId", bean.userId);
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                context.startActivity(intent);
            }
        });

        if (bean.praiseNum == 0) {
            holder.praiseNum.setText("");
        } else {
            String pNum = Integer.toString(bean.praiseNum);
            holder.praiseNum.setText(pNum);
        }

        if (bean.commentNum == 0) {
            holder.commentNum.setText("0");
        } else {
            String cNum = Integer.toString(bean.commentNum);
            holder.commentNum.setText(cNum);
        }

        holder.llcommentNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MyTopicDetail.class);
                intent.putExtra("topicId", bean.topicId);
                intent.putExtra("option", "comment");
                context.startActivity(intent);

            }
        });
//        holder.llGood.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(context, ClickLikeListActivity.class);
//                intent.putExtra("topicId", bean.topicId);
//                intent.putExtra("option", "comment");
//                context.startActivity(intent);
//            }
//        });

        holder.llshare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareSDK.initSDK(context);
                OnekeyShare oks = new OnekeyShare();
                // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
                oks.setTitleUrl(bean.shareUrl);
                oks.setTitle(Constant.SHARE_TITLE);
//        String loginid=SjtMainActivity.mainSharePreferences.getString("loginid","");
//        oks.setImagePath(Constant.CAMERA_PICTURE_PATH + loginid);
                oks.setImageUrl(Constant.ImageHost_Big + bean.itemImageResid);
                // text是分享文本，所有平台都需要这个字段
                oks.setText(bean.itemContent);
//        oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
                oks.setUrl(bean.shareUrl);
                // site是分享此内容的网站名称，仅在QQ空间使用
//        oks.setSite(getString(R.string.app_name));
                oks.show(context);


            }
        });
////九宫格图片显示（开始）
//        holder.img1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 0);
//            }
//        });
//        holder.img2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 1);
//            }
//        });
//        holder.img3.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 2);
//            }
//        });
//        holder.img4.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 3);
//            }
//        });
//        holder.img5.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 4);
//            }
//        });
//        holder.img6.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 5);
//            }
//        });
//        holder.img7.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 6);
//            }
//        });
//        holder.img8.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 7);
//            }
//        });
//        holder.img9.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showImage(position, 8);
//            }
//        });
//
//        //九宫格图片显示（结束）

        holder.llpraiseNum.setOnClickListener(new View.OnClickListener() {                  //点赞
            @Override
            public void onClick(View v) {
                StringRequest stringRequest3 = new StringRequest(Request.Method.POST, Constant.TopicPraiseHost, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        try {
                            JSONTokener jsonTokener = new JSONTokener(s);
                            JSONObject res = (JSONObject) jsonTokener.nextValue();
                            String code = res.getString("code");
                            String Message = res.getString("message");
                            if (code.equals("200")) {
                                JSONObject data = res.getJSONObject("data");
                                String praiseNum = data.getString("praiseNum");
                                String praiseSwitch = data.getString("praiseSwitch");
                                try {//取得点赞数赋值给当前
                                    mDataList.get(position).praiseNum = Integer.parseInt(praiseNum);
                                } catch (NumberFormatException e) {
                                    e.printStackTrace();
                                }

                                String mPraiseNameList = "";
                                JSONArray praiseList = data.getJSONArray("praiseList");
                                for (int j = 0;j<praiseList.length();j++){
                                    JSONObject praise =(JSONObject) praiseList.get(j);
                                    JSONObject auser = (JSONObject) praise.getJSONObject("user");
                                    SjtUser user1 = new SjtUser();
                                    user1.setSysid(auser.getString("sysId"));
                                    user1.setNickName(auser.getString("nickName"));
                                    user1.setImage(auser.getString("image"));
                                    if (j>0){
                                        String mName = "、"+user1.getNickName();
                                        mPraiseNameList+=mName;
                                    }else {
                                        mPraiseNameList+=user1.getNickName()+" ";
                                    }

                                    Praise praise1 = new Praise();
                                    praise1.setSysId(praise.getString("sysId"));
                                    praise1.setContent(praise.getString("content"));
                                    praise1.setCreateDateTime(praise.getString("createDateTime"));
                                    praise1.setUser(user1);
                                    mPraiseList.add(praise1);
                                }
//
                                mDataList.get(position).setPraiseList(mPraiseList);
                                mDataList.get(position).setPraiseNameList(mPraiseNameList);
                                android.os.Message message = new Message();
                                message.what = 1;
                                mHandler.sendMessage(message);
                                //点赞成功、取消提示
                                if (praiseSwitch.equals("1")) {
                                    Toast.makeText(context, context.getResources().getString(R.string.error_isgood_yes), Toast.LENGTH_LONG).show();
                                } else if (praiseSwitch.equals("0")) {
                                    Toast.makeText(context, context.getResources().getString(R.string.error_isgood_no), Toast.LENGTH_LONG).show();
                                }
                            } else {
                                Toast.makeText(context, Message, Toast.LENGTH_LONG).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                            Toast.makeText(context, context.getResources().getString(R.string.error_service), Toast.LENGTH_LONG).show();
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        Toast.makeText(context,context.getResources().getString(R.string.error_network), Toast.LENGTH_LONG).show();
                    }
                }) {
                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        String userId = context.getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE).getString("userId", "");
                        Map<String, String> map = new HashMap<>();
                        map.put("loginId", userId);
                        map.put("topicSysId", bean.topicId);
                        return map;
                    }

                    @Override
                    public Map<String, String> getHeaders() throws AuthFailureError {
                        String cookie = context.getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE).getString("cookie", "");
                        String rememberMeValue = context.getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE).getString("rememberMe", "");
                        HashMap localHashMap = new HashMap();
                        String cookieValue = cookie + ";" + rememberMeValue;
                        Log.e("cookie", cookieValue);
                        localHashMap.put("Cookie", cookieValue);
                        return localHashMap;
                    }
                };
                mQueue.add(stringRequest3);

            }
        });


//        if (bean.itemImageResid1.equals("null")) {
//            holder.llrow1.setVisibility(View.GONE);
//            holder.llrow2.setVisibility(View.GONE);
//            holder.llrow3.setVisibility(View.GONE);
//            holder.img1.setVisibility(View.GONE);
//        } else {
//            holder.llrow1.setVisibility(View.VISIBLE);
//            holder.llrow2.setVisibility(View.VISIBLE);
//            holder.llrow3.setVisibility(View.VISIBLE);
//            holder.img1.setVisibility(View.VISIBLE);
//            String imgUrl1 = Constant.ImageHost_Small + bean.itemImageResid1;
//            Glide.with(context).load(imgUrl).into(holder.img1);
//        }
//
//        if (bean.itemImageResid2.equals("null")) {
//            holder.img2.setVisibility(View.GONE);
//        } else {
//            holder.img2.setVisibility(View.VISIBLE);
//            String imgUrl2 = Constant.ImageHost_Small + bean.itemImageResid2;
//            Glide.with(context).load(imgUrl2).into(holder.img2);
//        }
//
//        if (bean.itemImageResid3.equals("null")) {
//            holder.img3.setVisibility(View.GONE);
//        } else {
//            holder.img3.setVisibility(View.VISIBLE);
//            String imgUrl3 = Constant.ImageHost_Big + bean.itemImageResid3;
//            Glide.with(context).load(imgUrl3).into(holder.img3);
//        }
//
//        if (bean.itemImageResid4.equals("null")) {
//            holder.llrow2.setVisibility(View.GONE);
//            holder.llrow3.setVisibility(View.GONE);
//            holder.img4.setVisibility(View.GONE);
//        } else {
//            holder.llrow2.setVisibility(View.VISIBLE);
//            holder.llrow3.setVisibility(View.VISIBLE);
//            holder.img4.setVisibility(View.VISIBLE);
//            String imgUrl4 = Constant.ImageHost_Small + bean.itemImageResid4;
//            Glide.with(context).load(imgUrl4).into(holder.img4);
//        }
//
//
//        if (bean.itemImageResid5.equals("null")) {
//            holder.img5.setVisibility(View.GONE);
//        } else {
//            holder.img5.setVisibility(View.VISIBLE);
//            String imgUrl5 = Constant.ImageHost_Small + bean.itemImageResid5;
//            Glide.with(context).load(imgUrl5).into(holder.img5);
//        }
//
//
//        if (bean.itemImageResid6.equals("null")) {
//            holder.img6.setVisibility(View.GONE);
//        } else {
//            holder.img6.setVisibility(View.VISIBLE);
//            String imgUrl6 = Constant.ImageHost_Small + bean.itemImageResid6;
//            Glide.with(context).load(imgUrl6).into(holder.img6);
//        }
//
//
//        if (bean.itemImageResid7.equals("null")) {
//            holder.llrow3.setVisibility(View.GONE);
//            holder.img7.setVisibility(View.GONE);
//        } else {
//            holder.llrow3.setVisibility(View.VISIBLE);
//            holder.img7.setVisibility(View.VISIBLE);
//            String imgUrl7 = Constant.ImageHost_Small + bean.itemImageResid7;
//            Glide.with(context).load(imgUrl7).into(holder.img7);
//        }
//
//
//        if (bean.itemImageResid8.equals("null")) {
//            holder.img8.setVisibility(View.GONE);
//        } else {
//            holder.img8.setVisibility(View.VISIBLE);
//            String imgUrl8 = Constant.ImageHost_Small + bean.itemImageResid8;
//            Glide.with(context).load(imgUrl8).into(holder.img8);
//        }
//
//
//        if (bean.itemImageResid9.equals("null")) {
//            holder.img9.setVisibility(View.GONE);
//        } else {
//            holder.img9.setVisibility(View.VISIBLE);
//            String imgUrl9 = Constant.ImageHost_Small + bean.itemImageResid9;
//            Glide.with(context).load(imgUrl9).into(holder.img9);
//        }


        //holder.img.setImageResource(bean.itemImageResid);
        holder.title.setText(user.getNickName());
        if ("".equals(bean.praiseNameList)||null==bean.praiseNameList){
            holder.ll_isgood.setVisibility(View.GONE);
        }else {
            holder.ll_isgood.setVisibility(View.VISIBLE);
        }
        holder.tv_isgood.setText(bean.praiseNameList);
        holder.time.setText(bean.itemTime);
        String textContent = bean.itemContent;
        textContent = textContent.replaceAll("\\[.{2,3}\\]", "[表情]");
        holder.content.setText(textContent);
        showComment(bean);
        mShowImage(bean,position);
        //holder.img1.setImageResource(bean.itemImageResid1);
//        long end = System.nanoTime();
//        long dValue = end - start;
//        mSumTime += dValue;
        //输出每次getView消耗的时间和
        //Log.d("xys", String.valueOf(mSumTime));
        return convertView;
        // 文艺式 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>16325820
    }
    public void showComment(ItemBean bean){
        holder.llcomment.setVisibility(View.GONE);
        holder.llcomment1.setVisibility(View.GONE);
        holder.llcomment2.setVisibility(View.GONE);
        holder.llcomment3.setVisibility(View.GONE);
        holder.ll_look_all_comment.setVisibility(View.GONE);
        if (bean.commentList.size()>0){
            holder.llcomment.setVisibility(View.VISIBLE);
            for (int i = 0 ;i<bean.commentList.size();i++){
                if (i==0){
                    holder.llcomment1.setVisibility(View.VISIBLE);
                    holder.tvCommentName1.setText(bean.commentList.get(0).getUser().getNickName()+":");
                    holder.tvComment1.setText(bean.commentList.get(0).getContent());
                }
                if (i==1){
                    holder.llcomment2.setVisibility(View.VISIBLE);
                    holder.tvCommentName2.setText(bean.commentList.get(1).getUser().getNickName()+":");
                    holder.tvComment2.setText(bean.commentList.get(1).getContent());
                }
                if (i==2){
                    holder.ll_look_all_comment.setVisibility(View.VISIBLE);
                    holder.llcomment3.setVisibility(View.VISIBLE);
                    holder.tvCommentName3.setText(bean.commentList.get(2).getUser().getNickName()+":");
                    holder.tvComment3.setText(bean.commentList.get(2).getContent());
                }
            }
        }
    }
    private void deleteTopic(final String topicId, final int position) {
        //显示Progress Dialog
        TipUtil.openProgressDialog(Constant.APPLICATION_NAME, context.getResources().getString(R.string.error_please_waitting), context);
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.DeleteTopicHost, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TipUtil.log("删除话题接口成功返回", response.toString(), 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {//成功
                        TipUtil.closeProgressDialog();
//                        Message msg = new Message();
//                        msg.what = 2;
//                        MineTabSquareFragment.mHandler.sendMessage(msg);
                        mDataList.remove(position);
                        notifyDataSetChanged();

                        Message msg1 = new Message();
                        msg1.what = 2;
                        SocialTabSquareFragment.mHandler.sendMessage(msg1);

                    } else {//失败
                        TipUtil.showToast(message, context, 1);
                    }
                } catch (JSONException ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(context.getResources().getString(R.string.error_service), context, 1);
                }
                TipUtil.closeProgressDialog();

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(context.getResources().getString(R.string.error_network), context, 1);
                TipUtil.closeProgressDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                SharedPreferences mainSharedPreferences = context.getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String userId = mainSharedPreferences.getString("userId", "");
                map.put("loginId", userId);
                map.put("sysId", topicId);
                return map;

            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences = context.getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
//                Log.e("cookie", cookieValue);
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);
    }


    // ViewHolder用于缓存控件
    private static class ViewHolder {
//        public NetworkImageView img;
        public RoundedImageView img;
        public TextView title;
        public TextView time;
        public TextView content;
        public ImageView img1;
        public ImageView img2;
        public ImageView img3;
        public ImageView img4;
        public ImageView img5;
        public ImageView img6;
        public ImageView img7;
        public ImageView img8;
        public ImageView img9;
        public LinearLayout llrow1;
        public LinearLayout llrow2;
        public LinearLayout llrow3;
        public TextView praiseNum;
        public TextView commentNum;

        public LinearLayout llpraiseNum;
        public LinearLayout llcommentNum;
        public LinearLayout llshare;
        public LinearLayout lldelete;
//        public LinearLayout llGood;
        public TextView tvIsGood;
        public LinearLayout ll_isgood;

        public TextView icon_linear_like;
        public TextView icon_information;
        public TextView icon_trash;
        public TextView icon_share;
        public TextView icon_jump;

        public LinearLayout llcomment;
        public LinearLayout llcomment1;
        public LinearLayout llcomment2;
        public LinearLayout llcomment3;

        public TextView tvCommentName1;
        public TextView tvCommentName2;
        public TextView tvCommentName3;

        public TextView tvComment1;
        public TextView tvComment2;
        public TextView tvComment3;
        public LinearLayout ll_look_all_comment;

        public TextView tv_isgood;
    }
    private void mShowImage(ItemBean bean,int position){
        LisetImageView.clear();
        holder.img1.setVisibility(View.GONE);
        LisetImageView.add(holder.img1);
        holder.img2.setVisibility(View.GONE);
        LisetImageView.add(holder.img2);
        holder.img3.setVisibility(View.GONE);
        LisetImageView.add(holder.img3);
        holder.img4.setVisibility(View.GONE);
        LisetImageView.add(holder.img4);
        holder.img5.setVisibility(View.GONE);
        LisetImageView.add(holder.img5);
        holder.img6.setVisibility(View.GONE);
        LisetImageView.add(holder.img6);
        holder.img7.setVisibility(View.GONE);
        LisetImageView.add(holder.img7);
        holder.img8.setVisibility(View.GONE);
        LisetImageView.add(holder.img8);
        holder.img9.setVisibility(View.GONE);
        LisetImageView.add(holder.img9);
        String [] newsplitstr = bean.getItemImage().split("\\|");
        final String[] imageUrls = new String[newsplitstr.length];

        holder.llrow1.setVisibility(View.GONE);
        holder.llrow2.setVisibility(View.GONE);
        holder.llrow3.setVisibility(View.GONE);
        if (newsplitstr.length!=0){
            holder.llrow1.setVisibility(View.VISIBLE);}
        if (newsplitstr.length>3){
            holder.llrow2.setVisibility(View.VISIBLE);}
        if (newsplitstr.length>6){
            holder.llrow3.setVisibility(View.VISIBLE);}
        for (int i=0;i<newsplitstr.length;i++){
            String aimgUrl = Constant.ImageHost_Small + newsplitstr[i];
            imageUrls[i] = Constant.ImageHost_Big + newsplitstr[i];
//            Log.e("i",i+"");
            ImageView ShowView = LisetImageView.get(i);
            ShowView.setVisibility(View.VISIBLE);
            Glide.with(context).load(aimgUrl).into(ShowView);
        }
        //九宫格图片显示（开始）
        holder.img1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 0);
            }
        });
        holder.img2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 1);
            }
        });
        holder.img3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 2);
            }
        });
        holder.img4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 3);
            }
        });
        holder.img5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 4);
            }
        });
        holder.img6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 5);
            }
        });
        holder.img7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 6);
            }
        });
        holder.img8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 7);
            }
        });
        holder.img9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage(imageUrls, 8);
            }
        });

        //九宫格图片显示（结束）

    }
    private void showImage(String[] imageUrls, int dot) {

        Intent intent = new Intent(context, ZonePictureActivity.class);
        intent.putExtra(IBaseConstant.PICTURE_VIEWER_DEFAULT_POSTION, dot);
        intent.putExtra(IBaseConstant.PICTURE_VIEWER_DATASOURCE, imageUrls);
        context.startActivity(intent);
    }

//    private void showImage(int position, int dot) {
//
//        String[] imageUrls = new String[pictureSize(position)];
//        for (int i = 0; i < pictureSize(position); i++) {
//            if (i == 0) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid1;
//            }
//            if (i == 1) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid2;
//            }
//            if (i == 2) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid3;
//            }
//            if (i == 3) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid4;
//            }
//            if (i == 4) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid5;
//            }
//            if (i == 5) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid6;
//            }
//            if (i == 6) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid7;
//            }
//            if (i == 7) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid8;
//            }
//            if (i == 8) {
//                imageUrls[i] = Constant.ImageHost_Big + mDataList.get(position).itemImageResid9;
//            }
//        }
//        Intent intent = new Intent(context, ZonePictureActivity.class);
//        intent.putExtra(IBaseConstant.PICTURE_VIEWER_DEFAULT_POSTION, dot);
//        intent.putExtra(IBaseConstant.PICTURE_VIEWER_DATASOURCE, imageUrls);
//        context.startActivity(intent);
//    }

//    private int pictureSize(int position) {
//        int i = 0;
//        if (!mDataList.get(position).itemImageResid1.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid2.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid3.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid4.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid5.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid6.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid7.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid8.equals("null")) {
//            i++;
//        }
//        if (!mDataList.get(position).itemImageResid9.equals("null")) {
//            i++;
//        }
//        return i;
//    }


}
